const signer = require('./utils/sign');

const moment = require('moment')

let currentTime =  moment(Date.now()).format('YYYYMMDDTHHmmss') + 'Z';
console.log(currentTime);

/*const key = crypto.randomBytes(16).toString('hex');*/
const data = "123456|" + currentTime;
const key = "aa15f4e579304eb585181015f5ef83f6";
const nonce = 'thisismust16byte';
/*const iv = Buffer.from(ivBase64, 'base64').toString('hex');
console.log("iv: " + iv);
*/
const signTxt = signer.encrypt(data, key, nonce);
console.log("sign: " + signTxt);

const decodeTxt = signer.decrypt(signTxt, key, nonce);
console.log("plainTxt: " + decodeTxt);

/*
const CryptoJS = require("crypto-js");

const data = "123456|20200810T150324Z";
const key = "aa15f4e579304eb585181015f5ef83f6";

var keyBuffer = Buffer.from(key, 'hex').toString();
console.log(keyBuffer);

// Encrypt
var ciphertext = CryptoJS.AES.encrypt(data, keyBuffer).toString();
console.log("sign: " + ciphertext);

// Decrypt
var bytes  = CryptoJS.AES.decrypt(ciphertext, keyBuffer);
var originalText = bytes.toString(CryptoJS.enc.Utf8);
console.log("plainTxt: " + originalText);
*/